<?php	
		//$Id: pulldown.php 369 2009-03-01 10:15:56Z cameron.bracken $
		
		//Creates a pulldown menu listing previous runs, also does a little cleanup
		//NOTE: this script is run from whe website root not the chunks directory

		include("chunks/cleanup.php");
		include("sandbox/www/vars.php");
		
		// Show what file the data was loaded from
		// if the file doesn't exist show an erroe
		if(!file_exists($loaded_run_file)){
			echo "<p style='color:red'>Error: Could not open run file, please load another file.</p>\n";			
		}else{
			$lines = file($loaded_run_file);
			$loaded_rundes = $lines[0];
			echo "<p>Currently Displaying data from: <span style='color:black'><b>$loaded_rundes</b></p>";
		}
		
		// Display the names of the previous runs in a pull down menu
		echo "<p style='margin:0;padding:0'>Select a different run to load:</p>";
		echo "<select name='run_file_to_load'>\n";
		$filenames = array_reverse(glob("$runsdir/*-*"));
		
		// this loop checks if there are more than $max_saved_runs
		// files in the $runsdir and deletes the oldest files if there 
		// are too many, otherwise display the name in the pulldown menu
		$i = 0;
		echo "$filenames";
		foreach ($filenames as $filename) {
			$i++;
			if($i > $max_saved_runs){
				//remove extra files
				unlink($filename);
			}else{
				//list the run description in the pulldown menu
				$lines = file($filename);
				$rundes = $lines[0];
				echo "<option value='$filename' ";
				if($filename==$loaded_run_file){echo"selected";}
				echo">$rundes</option>\n";
			}
		}
		echo "</select>\n";

?>